#include "stdafx.h"

#include "./glTypes.h"

#include "./glTrace.h"
#include "./glPict.h"


namespace GLES
{


	GLES::Bool Pict::createFromPVR( char* name )
	{
		
		PVRTextureHeader header;
		if(PVRTTextureLoadFromPVR(name, &_tex,&header) != PVR_SUCCESS)
		{
			xError1("PVRTTextureLoadFromPVR(%s)\n",name);
			return false;
		}
#ifdef WINCE
		_size.w = header.dwWidth;
		_size.h = header.dwHeight;
#else
		_size.w = header.u32Width;
		_size.h = header.u32Height;
#endif
		return true;
	}

	GLint Pict::getTexture()
	{
		return _tex;
	}

	SizeI Pict::setDesiredSize( SizeI size )
	{
		_size = size;
		return _size;
	}

	GLES::Void Pict::releaseTexture()
	{
		if(_tex)
		{
			glDeleteTextures(1, &_tex);
			_tex = 0;
		}
	}

	GLES::Bool Pict::createFromBuffer(SizeI& size,Uns32 format,Uns8* buff)
	{
		glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &_tex);
		glBindTexture(GL_TEXTURE_2D, _tex);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.w, size.h, 0, GL_RGBA, format, buff);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		_size = size;
		return true;
	}
}
